package com.ads.tpgrupo4.server.config;

import java.io.IOException;
import java.util.Properties;

import com.ads.tpgrupo4.server.utils.UriUtils;

public class Config {
	
	private static Config instance;
	private static Properties configProperties;
	
	public static Config getInstance() {
		
		if (instance == null) {

			instance = new Config();
			instance.init();
		}
		
		return instance;
	}
	
	public String getProperty(final String key) {

		return configProperties.getProperty(key);
	}
	
	private void init() {
		
		configProperties = new Properties();
		try {
			configProperties.load(Config.class.getClassLoader().getResourceAsStream(ConfigConstants.CONFIG_FILE_NAME));
		} catch (final IOException e) {
			e.printStackTrace();
		}
	}
	
	private Config() {
	}
	
	public String getMaestroDeRodamientosFilePath() {
		
		final String containingFolder = getProperty(ConfigConstants.SERVER_CONFIG_FILES_ROOT_FOLDER_PROPERTY);
		final String fileName = getProperty(ConfigConstants.SERVER_CONFIG_MAESTRO_DE_RODAMIENTOS_FILE_NAME_PROPERTY);		
		
		return UriUtils.buildPath(containingFolder, fileName);
	}
	
	public Double getPorcentajeDeGananciaDefaultPorItem() {
		
		final String percentageValue = getProperty(ConfigConstants.DEFAULT_PER_UNIT_PROFIT_PERCENTAGE);
		
		return Double.valueOf(percentageValue); 
	}
	
	public String getGeneratedFilesContainerDir() {
		
		return getProperty(ConfigConstants.GENERATED_FILES_CONTAINER_DIR);
	}

	public String getPublishedFilesBaseUrl() {
		
		return getProperty(ConfigConstants.PUBLISHED_FILES_BASE_URL);
	}
}
